package com.cyf.note11_19;

import com.alibaba.fastjson.JSON;

/*用java实现把对象转换成json,把json字符串转换成对象（推荐fastjson或者Gson）*/
public class question3_json {


    public static void main(String[] args) {

        //Java对象转化为json
        Person p = new Person("炊逸飞","男","cyf","1234");
        String json = JSON.toJSONString(p);
        System.out.println(json);

        //json转换成java对象
        String jsonObj = "{name:'炊逸飞',sex:'男',userName:'cyf',userPwd:123}";
        Person pobj = JSON.parseObject(jsonObj,Person.class);
        System.out.println(pobj.getName());
        System.out.println(pobj.getSex());
        System.out.println(pobj.getUserName());
        System.out.println(pobj.getUserPwd());
    }


}
